Repository navigation
Conversation
When the collector's DNS is unreachable, teardown of the curl transport could block host process exit for the system resolver timeout (tens of seconds). curl_easy_perform() does not run the progress callback while a name is resolving, so Abort() waited for the 5s connect timeout, and curl_easy_cleanup()/curl_multi_cleanup() then joined the resolver thread still blocked in getaddrinfo(). Set CURLOPT_QUICK_EXIT on every handle, and run modern-libcurl transfers on a private multi handle with CURLMOPT_QUICK_EXIT, polling the abort flag every 100ms. Option ids are passed numerically so a runtime libcurl newer than the build headers still receives them. A Linux unit test interposes getaddrinfo() to stall deterministically; it hangs 60s without this change. Files changed: - lib/http/HttpClient_Curl.hpp - tests/unittests/CMakeLists.txt - tests/unittests/HttpClientCurlTests.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ff620832-ec83-4315-b3e0-6f5d825d45e1
Include the integer type dependency in ICdsFactory.hpp and avoid the racy mkdir implementation in build-runner-tests.py. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: ea7f5226-1c17-476f-abaa-90cfa4b32e3c
CURLOPT_QUICK_EXIT lets teardown skip joining a resolver thread blocked in getaddrinfo(). That thread later returns into libcurl, so unloading the module that holds libcurl first (a shared libcurl losing its last reference, or a library that links it statically) would crash. When an aborted or timed-out transfer never finished name resolution, pin libcurl's module once with dlopen(RTLD_NOLOAD | RTLD_NODELETE). Hosts that never stall can still unload the module; the rare stalled case leaks the mapping instead of crashing. The DNS-stall test now checks the pin. Files changed: - lib/http/HttpClient_Curl.hpp - tests/unittests/HttpClientCurlTests.cpp Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 75770221-1676-4767-bba3-18994bc39f5f
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved resolver-lifetime and loader-lock issues can cause crashes or deadlocks during libcurl module unload.
4 open issues
What changed in this PR
This PR aims to prevent stalled DNS lookups from blocking curl transport teardown while protecting libcurl from unsafe unloading.
Changes:
- Adds abortable multi-handle transfers, quick-exit options, and module pinning.
- Adds a Linux stalled-DNS regression test and loader-library linkage.
- Hardens build-runner tests and adds a missing integer-type include.
| File | Description |
|---|---|
| tests/unittests/HttpClientCurlTests.cpp | Tests teardown during stalled DNS resolution. |
| tests/unittests/CMakeLists.txt | Links Linux tests with dynamic-loader support. |
| tests/build-runner-tests.py | Makes concurrent-child selection independent of mkdir. |
| lib/include/public/ICdsFactory.hpp | Includes integer-type definitions explicitly. |
| lib/http/HttpClient_Curl.hpp | Adds cancellation polling, quick-exit cleanup, and module pinning. |
Review effort: Balanced
r4811531007: pin before worker startup to avoid loader-lock deadlocks during teardown. Verified at lib/http/HttpClient_Curl.hpp:119,378. r4811531023: detect runtime support independently of header version and protect legacy easy transfers. Verified at lib/http/HttpClient_Curl.hpp:365-389. r4811531035: gate multi quick-exit on established module lifetime protection, including successful cleanup. Verified at lib/http/HttpClient_Curl.hpp:387,1067-1078. r4811531043: disable inherited proxies so the DNS regression test reaches its stalled hostname. Verified at tests/unittests/HttpClientCurlTests.cpp:1308-1350. Files changed: lib/http/HttpClient_Curl.hpp; tests/unittests/HttpClientCurlTests.cpp. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b759695a-3b22-4233-8d5e-fa894dcdb031
There was a problem hiding this comment.
🟡 Changes recommended
Relative executable paths can incorrectly disable quick-exit and leave teardown blocked by stalled DNS, while module-unload and successful-transfer cleanup regressions remain untested.
2 open issues
4 resolved since last review
Review effort: Balanced
4813699957: identify the main executable by its loaded mapping instead of a current-directory-sensitive path, with a chdir regression. 4813699987: add isolated fetched-curl unload regressions for stalled resolver release after dlclose and idle workers after a successful transfer. Files changed: lib/http/HttpClient_Curl.hpp; tests/unittests/CMakeLists.txt; tests/unittests/HttpClientCurlTests.cpp; tests/unittests/curl-module-unload-module.cpp; tests/unittests/curl-module-unload-test-api.hpp; tests/unittests/curl-module-unload-test.cpp. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b759695a-3b22-4233-8d5e-fa894dcdb031
4813831962: keep curl_multi_poll and curl_multi_wait optional at load time; use bounded multi polling when available and retain the legacy easy path otherwise. 4813831981 and 4813699987: route a reserved test hostname through the controlled resolver to loopback and require its return before teardown, ensuring the successful transfer leaves a real resolver worker idle. Files changed: lib/http/HttpClient_Curl.hpp; tests/unittests/curl-module-unload-test.cpp. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b759695a-3b22-4233-8d5e-fa894dcdb031
There was a problem hiding this comment.
🟡 Changes recommended
The load-time compatibility fallback lacks regression coverage for runtimes missing optional symbols, leaving accidental strong references that could prevent SDK loading undetected.
2 open issues
2 resolved since last review
Review effort: Balanced
4813891935: add system-libcurl shims that omit curl_multi_poll, then omit both poll and wait. The load-only host verifies the selected shim is mapped and dlopens the SDK module with RTLD_NOW, catching strong references before runtime fallback can run. Files changed: tests/unittests/CMakeLists.txt; tests/unittests/curl-optional-symbol-load-module.cpp; tests/unittests/curl-optional-symbol-load-test.cpp; tests/unittests/curl-runtime-shim.cpp. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: b759695a-3b22-4233-8d5e-fa894dcdb031


Problem
The Linux curl transport could stall host shutdown when DNS is unreachable.
curl_easy_perform()does not run its progress callback during name resolution, and resolver cleanup may wait for a worker blocked ingetaddrinfo().Fix
RTLD_NODELETE. If an unloadable module cannot be pinned, quick-exit remains disabled.curl_multi_pollandcurl_multi_waitoptional at load time when headers are newer than runtime libcurl. Use whichever bounded multi wait API is available, and fall back tocurl_easy_perform()only if neither is present.CURLMOPT_QUICK_EXITonly when supported and protected. This covers resolver workers detached after both failed and successful transfers; legacy easy transfers are protected too.CURLOPT_NOPROXYon the stalled-DNS regression test's easy handle so proxy environment settings cannot bypass the intercepted hostname.Unload tradeoff: When quick-exit is used, libcurl's module remains mapped for the process lifetime, including after successful transfers, because idle resolver workers may also be detached. This avoids both loader-lock deadlocks from worker-thread pinning and use-after-unload crashes.
Tests
HttpClientCurlDnsStallTests.DestroyingClientDuringStalledResolutionDoesNotHanginterceptsgetaddrinfo()fordns-stall.invalidonly, confirms client teardown completes within 3 seconds, and checks for one terminal response. It skips on runtimes without the required async resolver/quick-exit support.HttpClientCurlModuleTests.IdentifiesMainExecutableAfterWorkingDirectoryChangeschecks main-image recognition afterchdir().dlcloseand module retention after a successful transfer leaves a resolver worker idle. The success case routes a reserved.invalidhostname through the test resolver to loopback and requires the resolver to return before teardown.libcurl.so.4shims to omitcurl_multi_poll, then both optional wait symbols, and verify the SDK module still loads withRTLD_NOW.Validation (WSL Ubuntu 24.04)
HttpClientCurl*, system libcurl 8.5UnitTests, system libcurl 8.5HttpClientCurl*, fetched libcurl 8.21UnitTests, fetched libcurl 8.21git diff --check